home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / sphigs / sph_quik.lha / quickdraw / src / shape_calls.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-09  |  11.8 KB  |  595 lines

  1. /*------------------------------ shape_calls.c -------------------------------*/
  2. /* Copyright 1989 Brown University -- Jeffrey Vogel                           */
  3. /*----------------------------------------------------------------------------*/
  4.  
  5.  
  6. /*--------------------------------- Includes ---------------------------------*/
  7. /*----------------------------------------------------------------------------*/
  8.  
  9. #include "qd_local.h"
  10.  
  11.  
  12.  
  13. /*--------------------------------- DrawLine ---------------------------------*/
  14. /*----------------------------------------------------------------------------*/
  15.  
  16. void
  17. DrawLine(p1, p2)
  18. Point  p1, p2;
  19. {
  20.    /*** error check ***/
  21.    if (!QDrunning) {
  22.       QDerror("ERROR DrawLine: QuickDraw not initialized.");
  23.       return;
  24.    }
  25.  
  26.    XDrawLine(QDdisplay, QDwindow, QDgc,
  27.                   p1.x, p1.y,
  28.                   p2.x, p2.y);
  29.    XFlush(QDdisplay);
  30. }
  31.  
  32.  
  33. /*-------------------------------- EraseLine ---------------------------------*/
  34. /*----------------------------------------------------------------------------*/
  35.  
  36. void
  37. EraseLine(p1, p2)
  38. Point  p1, p2;
  39. {
  40.    /*** error check ***/
  41.    if (!QDrunning) {
  42.       QDerror("ERROR EraseLine: QuickDraw not initialized.");
  43.       return;
  44.    }
  45.  
  46.    XSetFunction(QDdisplay, QDgc, GXclear);
  47.    XDrawLine(QDdisplay, QDwindow, QDgc, 
  48.                   p1.x, p1.y,
  49.                   p2.x, p2.y);
  50.    XFlush(QDdisplay);
  51.    XChangeGC(QDdisplay, QDgc, GCFunction, &QDgcValues);
  52. }
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. /*-------------------------------- FrameRect ---------------------------------*/
  68. /*----------------------------------------------------------------------------*/
  69.  
  70. void
  71. FrameRect(rect)
  72. Rect  rect;
  73. {
  74.    /*** error check ***/
  75.    if (!QDrunning) {
  76.       QDerror("ERROR FrameRect: QuickDraw not initialized.");
  77.       return;
  78.    }
  79.    if ((rect.left > rect.right) ||
  80.        (rect.top > rect.bottom)) {
  81.       QDerror("ERROR FrameRect: Invalid rectangle.");
  82.       return;
  83.    }
  84.  
  85.    XDrawRectangle(QDdisplay, QDwindow, QDgc,
  86.                   rect.left, rect.top,
  87.                   rect.right - rect.left,
  88.                   rect.bottom - rect.top);
  89.    XFlush(QDdisplay);
  90. }
  91.  
  92.  
  93. /*-------------------------------- PaintRect ---------------------------------*/
  94. /*----------------------------------------------------------------------------*/
  95.  
  96. void
  97. PaintRect(rect)
  98. Rect  rect;
  99. {
  100.    /*** error check ***/
  101.    if (!QDrunning) {
  102.       QDerror("ERROR PaintRect: QuickDraw not initialized.");
  103.       return;
  104.    }
  105.    if ((rect.left > rect.right) ||
  106.        (rect.top > rect.bottom)) {
  107.       QDerror("ERROR PaintRect: Invalid rectangle.");
  108.       return;
  109.    }
  110.  
  111.    XFillRectangle(QDdisplay, QDwindow, QDgc,
  112.                   rect.left, rect.top,
  113.                   rect.right - rect.left + 1,
  114.                   rect.bottom - rect.top + 1);
  115.    XFlush(QDdisplay);
  116. }
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133. /*-------------------------------- InvertRect --------------------------------*/
  134. /*----------------------------------------------------------------------------*/
  135.  
  136. void
  137. InvertRect(rect)
  138. Rect  rect;
  139. {
  140.    /*** error check ***/
  141.    if (!QDrunning) {
  142.       QDerror("ERROR InvertRect: QuickDraw not initialized.");
  143.       return;
  144.    }
  145.    if ((rect.left > rect.right) ||
  146.        (rect.top > rect.bottom)) {
  147.       QDerror("ERROR InvertRect: Invalid rectangle.");
  148.       return;
  149.    }
  150.  
  151.    XFillRectangle(QDdisplay, QDwindow, QDinvertgc,
  152.                   rect.left, rect.top,
  153.                   rect.right - rect.left + 1,
  154.                   rect.bottom - rect.top + 1);
  155.    XFlush(QDdisplay);
  156. }
  157.  
  158.  
  159. /*-------------------------------- EraseRect ---------------------------------*/
  160. /*----------------------------------------------------------------------------*/
  161.  
  162. void
  163. EraseRect(rect)
  164. Rect  rect;
  165. {
  166.    int offset = QDgcValues.line_width;
  167.  
  168.    /*** error check ***/
  169.    if (!QDrunning) {
  170.       QDerror("ERROR EraseRect: QuickDraw not initialized.");
  171.       return;
  172.    }
  173.    if ((rect.left > rect.right) ||
  174.        (rect.top > rect.bottom)) {
  175.       QDerror("ERROR EraseRect: Invalid rectangle.");
  176.       return;
  177.    }
  178.  
  179.    XSetFunction(QDdisplay, QDgc, GXclear);
  180.    XFillRectangle(QDdisplay, QDwindow, QDgc, 
  181.             rect.left, rect.top,
  182.             rect.right - rect.left + 1,
  183.             rect.bottom - rect.top + 1);
  184.    XFlush(QDdisplay);
  185.    XChangeGC(QDdisplay, QDgc, GCFunction, &QDgcValues);
  186. }
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199. /*-------------------------------- FrameOval ---------------------------------*/
  200. /*----------------------------------------------------------------------------*/
  201.  
  202. void
  203. FrameOval(rect)
  204. Rect  rect;
  205. {
  206.    /*** error check ***/
  207.    if (!QDrunning) {
  208.       QDerror("ERROR FrameOval: QuickDraw not initialized.");
  209.       return;
  210.    }
  211.    if ((rect.left > rect.right) ||
  212.        (rect.top > rect.bottom)) {
  213.       QDerror("ERROR FrameOval: Invalid rectangle.");
  214.       return;
  215.    }
  216.  
  217.    XDrawArc(QDdisplay, QDwindow, QDgc, 
  218.             rect.left, rect.top,
  219.             rect.right - rect.left,
  220.             rect.bottom - rect.top,
  221.             0, 360 * 64);
  222.    XFlush(QDdisplay);
  223. }
  224.  
  225. /*-------------------------------- PaintOval ---------------------------------*/
  226. /*----------------------------------------------------------------------------*/
  227.  
  228. void
  229. PaintOval(rect)
  230. Rect  rect;
  231. {
  232.    /*** error check ***/
  233.    if (!QDrunning) {
  234.       QDerror("ERROR PaintOval: QuickDraw not initialized.");
  235.       return;
  236.    }
  237.    if ((rect.left > rect.right) ||
  238.        (rect.top > rect.bottom)) {
  239.       QDerror("ERROR PaintOval: Invalid rectangle.");
  240.       return;
  241.    }
  242.  
  243.    XFillArc(QDdisplay, QDwindow, QDgc, 
  244.             rect.left, rect.top,
  245.             rect.right - rect.left + 1,
  246.             rect.bottom - rect.top + 1,
  247.             0, 360 * 64);
  248.    XFlush(QDdisplay);
  249. }
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265. /*-------------------------------- InvertOval --------------------------------*/
  266. /*----------------------------------------------------------------------------*/
  267.  
  268. void
  269. InvertOval(rect)
  270. Rect  rect;
  271. {
  272.    /*** error check ***/
  273.    if (!QDrunning) {
  274.       QDerror("ERROR InvertOval: QuickDraw not initialized.");
  275.       return;
  276.    }
  277.    if ((rect.left > rect.right) ||
  278.        (rect.top > rect.bottom)) {
  279.       QDerror("ERROR InvertOval: Invalid rectangle.");
  280.       return;
  281.    }
  282.  
  283.    XFillArc(QDdisplay, QDwindow, QDinvertgc, 
  284.             rect.left, rect.top,
  285.             rect.right - rect.left + 1,
  286.             rect.bottom - rect.top + 1,
  287.             0, 360 * 64);
  288.    XFlush(QDdisplay);
  289. }
  290.  
  291. /*-------------------------------- EraseOval ---------------------------------*/
  292. /*----------------------------------------------------------------------------*/
  293.  
  294. void
  295. EraseOval(rect)
  296. Rect  rect;
  297. {
  298.    /*** error check ***/
  299.    if (!QDrunning) {
  300.       QDerror("ERROR EraseOval: QuickDraw not initialized.");
  301.       return;
  302.    }
  303.    if ((rect.left > rect.right) ||
  304.        (rect.top > rect.bottom)) {
  305.       QDerror("ERROR EraseOval: Invalid rectangle.");
  306.       return;
  307.    }
  308.  
  309.    XSetFunction(QDdisplay, QDgc, GXclear);
  310.    XFillArc(QDdisplay, QDwindow, QDgc, 
  311.             rect.left, rect.top,
  312.             rect.right - rect.left + 1,
  313.             rect.bottom - rect.top + 1,
  314.             0, 360 * 64);
  315.    XFlush(QDdisplay);
  316.    XChangeGC(QDdisplay, QDgc, GCFunction, &QDgcValues);
  317. }
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331. /*--------------------------------- FrameArc ---------------------------------*/
  332. /*----------------------------------------------------------------------------*/
  333.  
  334. void
  335. FrameArc(rect, start, angle)
  336. Rect     rect;
  337. int      start, angle;
  338. {
  339.    if (!QDrunning) {
  340.       QDerror("ERROR FrameArc: QuickDraw not initialized.");
  341.       return;
  342.    }
  343.    if ((rect.left > rect.right) ||
  344.        (rect.top > rect.bottom)) {
  345.       QDerror("ERROR FrameArc: Invalid rectangle.");
  346.       return;
  347.    }
  348.  
  349.    XDrawArc(QDdisplay, QDwindow, QDgc, 
  350.             rect.left, rect.top,
  351.             rect.right - rect.left,
  352.             rect.bottom - rect.top,
  353.             64 * (90 - start - angle), 64 * angle);
  354.    XFlush(QDdisplay);
  355. }
  356.  
  357.  
  358.  
  359.  
  360. /*--------------------------------- PaintArc ---------------------------------*/
  361. /*----------------------------------------------------------------------------*/
  362.  
  363. void
  364. PaintArc(rect, start, angle)
  365. Rect     rect;
  366. int      start, angle;
  367. {
  368.    /*** error check ***/
  369.     if (!QDrunning) {
  370.       QDerror("ERROR PaintArc: QuickDraw not initialized.");
  371.       return;
  372.    }
  373.    if ((rect.left > rect.right) ||
  374.        (rect.top > rect.bottom)) {
  375.       QDerror("ERROR PaintArc: Invalid rectangle.");
  376.       return;
  377.    }
  378.  
  379.    XFillArc(QDdisplay, QDwindow, QDgc, 
  380.             rect.left, rect.top,
  381.             rect.right - rect.left + 1,
  382.             rect.bottom - rect.top + 1,
  383.             64 * (90 - start - angle), 64 * angle);
  384.    XFlush(QDdisplay);
  385. }
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397. /*-------------------------------- InvertArc ---------------------------------*/
  398. /*----------------------------------------------------------------------------*/
  399.  
  400. void
  401. InvertArc(rect, start, angle)
  402. Rect     rect;
  403. int      start, angle;
  404. {
  405.    /*** error check ***/
  406.     if (!QDrunning) {
  407.       QDerror("ERROR InvertArc: QuickDraw not initialized.");
  408.       return;
  409.    }
  410.    if ((rect.left > rect.right) ||
  411.        (rect.top > rect.bottom)) {
  412.       QDerror("ERROR InvertArc: Invalid rectangle.");
  413.       return;
  414.    }
  415.  
  416.    XFillArc(QDdisplay, QDwindow, QDinvertgc, 
  417.             rect.left, rect.top,
  418.             rect.right - rect.left + 1,
  419.             rect.bottom - rect.top + 1,
  420.             64 * (90 - start - angle), 64 * angle);
  421.    XFlush(QDdisplay);
  422. }
  423.  
  424.  
  425.  
  426. /*--------------------------------- EraseArc ---------------------------------*/
  427. /*----------------------------------------------------------------------------*/
  428.  
  429. void
  430. EraseArc(rect, start, angle)
  431. Rect     rect;
  432. int      start, angle;
  433. {
  434.    /*** error check ***/
  435.    if (!QDrunning) {
  436.       QDerror("ERROR EraseArc: QuickDraw not initialized.");
  437.       return;
  438.    }
  439.    if ((rect.left > rect.right) ||
  440.        (rect.top > rect.bottom)) {
  441.       QDerror("ERROR EraseArc: Invalid rectangle.");
  442.       return;
  443.    }
  444.  
  445.    XSetFunction(QDdisplay, QDgc, GXclear);
  446.    XFillArc(QDdisplay, QDwindow, QDgc,
  447.             rect.left, rect.top,
  448.             rect.right - rect.left + 1,
  449.             rect.bottom - rect.top + 1,
  450.             64 * (90 - start - angle), 64 * angle);
  451.    XChangeGC(QDdisplay, QDgc, GCFunction, &QDgcValues);
  452.    XFlush(QDdisplay);
  453. }
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463. /*------------------------------- PaintCircle --------------------------------*/
  464. /*----------------------------------------------------------------------------*/
  465.  
  466. void
  467. PaintCircle(x, y, radius)
  468. int x, y, radius;
  469. {
  470.    /*** error check ***/
  471.     if (!QDrunning) {
  472.       QDerror("ERROR PaintCircle: QuickDraw not initialized.");
  473.       return;
  474.    }
  475.    if (radius <= 0) {
  476.       QDerror("ERROR PaintCircle: Invalid circle.");
  477.       return;
  478.    }
  479.  
  480.    XFillArc(QDdisplay, QDwindow, QDgc, 
  481.             x-radius, y-radius,
  482.             2*radius + 1, 2*radius + 1,
  483.             0, (64 * 360));
  484.  
  485.    XFlush(QDdisplay);
  486. }
  487.  
  488.  
  489.  
  490.  
  491.  
  492. /*------------------------------- FrameCircle --------------------------------*/
  493. /*----------------------------------------------------------------------------*/
  494.  
  495. void
  496. FrameCircle(x, y, radius)
  497. int x, y, radius;
  498. {
  499.    /*** error check ***/
  500.     if (!QDrunning) {
  501.       QDerror("ERROR FrameCircle: QuickDraw not initialized.");
  502.       return;
  503.    }
  504.    if (radius <= 0) {
  505.       QDerror("ERROR FrameCircle: Invalid circle.");
  506.       return;
  507.    }
  508.  
  509.    XDrawArc(QDdisplay, QDwindow, QDgc, 
  510.             x-radius, y-radius,
  511.             2*radius, 2*radius,
  512.             0, (64 * 360));
  513.  
  514.     XFlush(QDdisplay);
  515. }
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529. /*------------------------------- EraseCircle --------------------------------*/
  530. /*----------------------------------------------------------------------------*/
  531.  
  532. void
  533. EraseCircle(x, y, radius)
  534. int x, y, radius;
  535. {
  536.    /*** error check ***/
  537.     if (!QDrunning) {
  538.       QDerror("ERROR EraseCircle: QuickDraw not initialized.");
  539.       return;
  540.    }
  541.    if (radius <= 0) {
  542.       QDerror("ERROR EraseCircle: Invalid circle.");
  543.       return;
  544.    }
  545.  
  546.    XSetFunction(QDdisplay, QDgc, GXclear);
  547.    XFillArc(QDdisplay, QDwindow, QDgc, 
  548.             x-radius, y-radius,
  549.             2*radius + 1, 2*radius + 1,
  550.             0, (64 * 360));
  551.    XChangeGC(QDdisplay, QDgc, GCFunction, &QDgcValues);
  552.    XFlush(QDdisplay);
  553. }
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.